package com.example.campsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.campsystem.entity.Camps;
import com.example.campsystem.service.CampsService;
import com.example.campsystem.mapper.CampsMapper;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author GJC
* @description 针对表【camps(营地表)】的数据库操作Service实现
* @createDate 2025-04-20 23:23:47
*/
@Service
public class CampsServiceImpl extends ServiceImpl<CampsMapper, Camps>
    implements CampsService{
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    @Override
    public List<Camps> getCampList(Integer cityId, Integer categoryId, String keyword) {
        QueryWrapper<Camps> queryWrapper = new QueryWrapper<>();

        if (cityId != null) {
            queryWrapper.eq("city_id", cityId);
        }
        if (categoryId != null) {
            queryWrapper.eq("category_id", categoryId);
        }
        if (keyword != null && !keyword.isEmpty()) {
            queryWrapper.and(wrapper -> wrapper.like("name", keyword).or().like("description", keyword));
        }
        return this.list(queryWrapper);
    }
        public List<Map<String, Object>> selectlistbyuserid(Long userId) {
            CampsMapper campsMapper = sqlSessionTemplate.getMapper(CampsMapper.class);
            if (userId == null) {
                throw new IllegalArgumentException("用户ID不能为空");
            }
            return campsMapper.selectCampsByUserId(userId);
        }
    }





